/**
 * @filename:CourseServiceImpl Course
 * @project constract  V1.0
 * Copyright(c) 2018 gong Co. Ltd.
 * All right reserved.
 */
package com.znufe.exam.service.impl;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.znufe.exam.domain.course.CourseDirectoryObject;
import com.znufe.exam.domain.course.CoursePageResponseObject;
import com.znufe.exam.domain.course.CourseResponseObject;
import com.znufe.exam.viewmodel.student.course.CoursePageRequestVm;
import com.znufe.exam.viewmodel.student.course.CourseProjectRequestVm;
import com.znufe.exam.viewmodel.student.course.CourseSearchRequestVm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.znufe.exam.domain.Course;
import com.znufe.exam.repository.CourseMapper;
import com.znufe.exam.service.CourseService;

/**
 *
 * @Description:  课程表——SERVICEIMPL
 * @Author:       gong
 * @CreateDate:   Course
 * @Version:      V1.0
 *
 */
@Service
public class CourseServiceImpl extends BaseServiceImpl<Course> implements CourseService{

	private final CourseMapper courseMapper;

	@Autowired
    public CourseServiceImpl(CourseMapper courseMapper){
	    super(courseMapper);
	    this.courseMapper = courseMapper;
    }


    /**
     * 根据ID查询课程
     * @param   id
     * @return
     */
	@Override
	public Course selectByPrimaryKey(Integer id) {
		return courseMapper.selectByPrimaryKey(id);
	}

    /**
     * 根据主键删除课程
     * @param   id
     * @return
     */
	@Override
	public int deleteByPrimaryKey(Integer id) {
		return courseMapper.deleteByPrimaryKey(id);
	}

    /**
     * 添加课程
     * @param   course
     * @return
     */
	@Override
	public int insertSelective(Course course) {
		return courseMapper.insertSelective(course);
	}

    /**
     * 修改对象
     * @param   course
     * @return
     */
	@Override
	public int updateByPrimaryKeySelective(Course course) {
		return courseMapper.updateByPrimaryKeySelective(course);
	}

	//查询集合
	@Override
	public List<Course> queryCourseList(Course course) {
		return courseMapper.queryCourseList(course);
	}


    /**
     * @explain 根据级别查询4条相应课程
     * @param courseType
     * @param courseProject
     * @return
     */
    @Override
    public List<Course> queryCourseByProjectAndTypeLimit(Integer courseProject,Integer courseType) {
        return courseMapper.queryCourseByProjectAndTypeLimit(courseProject,courseType);
    }

    /**
     * @explain 查询更多课程,分页展示
     * @param requestVm
     * @return
     */
    @Override
    public PageInfo<Course> getCoursePageByType(CoursePageRequestVm requestVm) {
        return PageHelper.startPage(requestVm.getPageNum(),requestVm.getPageSize(),"gmt_create").
                doSelectPageInfo(()->courseMapper.getCoursePageByType(requestVm));
    }

    /**
     *
     * @param requestVm
     * @return
     */
    @Override
    public PageInfo<Course> queryCourseByTypeAndName(CourseSearchRequestVm requestVm) {
        return PageHelper.startPage(requestVm.getPageNum(),requestVm.getPageSize()).doSelectPageInfo(()->
                courseMapper.queryCourseByTypeAndName(requestVm));
    }

    /**
     * 分页展示课程信息
     * @param requestVM
     * @return
     */
    @Override
    public PageInfo<CoursePageResponseObject> coursePage(CoursePageRequestVm requestVM) {
        return PageHelper.startPage(requestVM.getPageNum(),requestVM.getPageSize(),"id desc").doSelectPageInfo(()->
                courseMapper.coursePage(requestVM));
    }

    /**
     * 根据项目类别、课程名称、课程类别查询课程
     * @param courseProject
     * @param courseName
     * @param courseType
     * @return
     */
    @Override
    public Course getCourseByProjectAndNameAndType(Integer courseProject, String courseName, Integer courseType) {
        return courseMapper.getCourseByProjectAndNameAndType(courseProject,courseName,courseType);
    }

    @Override
    public List<CourseResponseObject> getCourseOutlineById(Integer courseId) {
        return courseMapper.getCourseOutlineById(courseId);
    }

    @Override
    public List<Course> queryCourseByProjectAndType(Integer courseProject,Integer courseType,String orderByField) {
        return courseMapper.queryCourseByProjectAndType(courseProject,courseType,orderByField);
    }

    @Override
    public List<CourseDirectoryObject> getCourseDirectoryById(Integer courseId) {
        return courseMapper.getCourseDirectoryById(courseId);
    }

    @Override
    public int deleteAllCourseByCategory(Integer categoryId) {
        return courseMapper.deleteAllCourseByCategory(categoryId);
    }
}
